<?php
class Service_RestServiceStubBase
{
	protected $_serviceUriRoot;
	
	protected $_accessToken;  // access token retrieved from authentication
	
	protected $_requestContext; // array that contains information of the user in session

	public function __construct($serviceUriRoot, $accessToken, $contentType = 'application/json')
	{
		$this->_serviceUriRoot = $serviceUriRoot;
		$this->_accessToken = $accessToken;
		
		$config = array(
				'uri' => $this->_serviceUriRoot,
				'content_type' => $contentType
		);
		
		$this->_restClient = REST_Client::instance($this->_serviceUriRoot, $config);
	}
	
	public function init($requestContext)
	{
		$this->_requestContext = $requestContext;
	}
	
	public function getUserSid() {
		$sesionInfo = $this->_requestContext->sessionInfo;
		if ($sesionInfo != null && array_key_exists('userSid', $sesionInfo->userInfo))
			return $sesionInfo->userInfo['userSid'];
		return null;
	}
	public function getUserId() {
		$sesionInfo = $this->_requestContext->sessionInfo;
		if ($sesionInfo != null && array_key_exists('userId', $sesionInfo->userInfo))
			return $sesionInfo->userInfo['userId'];
		return null;
	}
	public function getDomainId() {
		if ($this->_requestContext != null )
			return $this->_requestContext->domainId;
		return null;
	}
	
	public function setAccessToken($accessToken)
	{
		$this->_accessToken = $accessToken;
	}
}